package cn.cloud9;

import java.util.Arrays;

public class Demo12ConcatString {

    /**
     * https://www.bilibili.com/video/BV18J411W7cE?p=124
     * 拼接字符串 把int数组 {1, 2, 3} 转换成 [1,2,3]
     * @param args
     */
    public static void main(String[] args) {
        int[] array = {1, 2, 3};

        // 最快办法
        String solution = Arrays.toString(array);
        System.out.println(solution);

        String solution2 = "[";
        // 自己处理
        for (int i = 0; i < array.length; i++) {
            if (i == array.length - 1) {
                solution2 += String.valueOf(array[i]).concat("]");
                break;
            }
            solution2 += String.valueOf(array[i]).concat(",");
        }
        System.out.println(solution2);

    }
}
